package com.cloudptt.wp.ui.more;
//Download by htp://www.codefans.net


import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.cloudptt.api.comm.CommInfo;
import com.cloudptt.api.models.VersionInfo;
import com.cloudptt.api.product.Product;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;
import com.cloudptt.wp.ScreenManager;
import com.cloudptt.wp.SysApplication;
import com.cloudptt.wp.ui.BaseActivity;
import com.cloudptt.wp.ui.main.MainActivity;

public class VersionInfoActivity extends BaseActivity implements OnClickListener {
	private final static String TAG = "VersionInfoActivity";
	private TextView returnBtn; 
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		Window window = getWindow();
//		window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
		//window.setStatusBarColor(getResources().getColor(R.color.app_theme_color_primary));
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_version);
		
//		getActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.app_theme_color_primary));
//		getActionBar().hide();
		
		TextView versionText = (TextView)findViewById(R.id.versionText);
		String str = getVersion();
		Log.d(TAG, "onCreate str "+ str);
		versionText.setText(str);

		TextView tv = (TextView) findViewById(R.id.titleTv);
		tv.setText(R.string.about_us);

		ScreenManager.getScreenManager().pushActivity(this);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		
		if(android.R.id.home == item.getItemId()){
			finish();
			return true;
		}
		
		return super.onOptionsItemSelected(item);
	}
	
	public void onClick(View v) {
		int id = v.getId();
//		if(id == R.id.back_up_icon)
//		{
//			this.finish();
//		}
	}
	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		Log.debug(VersionInfoActivity.class, "onKeyDown keyCode "+ keyCode);

		if (keyCode == KeyEvent.KEYCODE_SOFT_LEFT
				|| keyCode == 66)
		{
			SysApplication app = ((SysApplication) getApplicationContext());
			Product product = app.getProduct();
			product.checkCurVersion(VersionInfoActivity.this,true);
			return false;
		}
		else if (keyCode == 21)
		{
			return true;
		}
		else if (keyCode == 22)
		{
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		Log.debug(VersionInfoActivity.class, "onKeyUp keyCode "+ keyCode);
		return super.onKeyUp(keyCode, event);
	}

	/**
	 * 锟斤拷取锟芥本锟斤拷
	 * @return 锟斤拷前应锟矫的版本锟斤拷
	 */
	public String getVersion() {
	    try {
	    	CommInfo info = new CommInfo(this);
	    	VersionInfo verInfo = info.getVersionInfo();
	        String version = verInfo.getName() + "(" + verInfo.getVersionCode() + ")";
	        return version;
	    } catch (Exception e) {
	        e.printStackTrace();
	        return "";
	    }
	}

	public void login_back(View v) {     
		this.finish();
	}


	
}
